#include "StackUtils.h"
#include "IProtocol.h"
#include "ILayer.h"

ProtocolEncode::ProtocolEncode(CPacket& p) : packet(p)
{
}

void ProtocolEncode::operator()(boost::shared_ptr<IProtocol>& protocol)
{
	protocol->Encode(packet);
}

void ProtocolEncode::operator()( std::pair<const std::string, boost::shared_ptr<IProtocol> >& protocol )
{
	protocol.second->Encode(packet);
}

ProtocolDecode::ProtocolDecode(CPacket& p) : packet(p)
{
}

void ProtocolDecode::operator()(boost::shared_ptr<IProtocol>& protocol) 
{
	protocol->Decode(packet);
}

void ProtocolDecode::operator()( std::pair<const std::string, boost::shared_ptr<IProtocol> >& protocol )
{
	protocol.second->Decode(packet);
}

void StackUtils::init_layer( boost::shared_ptr<ILayer>& layer)
{
	layer->init();	
}

bool LayerComparer::operator()( const boost::shared_ptr<ILayer>& layer )
{
		if(layer->getName().compare(layer_name) == 0) 
		{
			return true;
		}

		return false;
}

LayerComparer::LayerComparer( const std::string& name ) : layer_name(name)
{

}

bool ProtocolComparer::operator()( const boost::shared_ptr<IProtocol>& protocol )
{
	if(protocol->getName().compare(protocol_name) == 0) 
	{
		return true;
	}

	return false;
}

bool ProtocolComparer::operator()( const std::pair<std::string,  boost::shared_ptr<IProtocol> >& map_protocol)
{
	if(map_protocol.second->getName().compare(protocol_name) == 0) 
	{
		return true;
	}

	return false;
}

ProtocolComparer::ProtocolComparer( const std::string& name ) : protocol_name(name)
{

}
